﻿procedure;  
var
  DS: TAppDataSet;
  SL: TStringList;
  
  LuP_ContenctMNUDS, LuP_DocumentItems : TAppDataSet;
  LuP_ID, LuP_Switch, LuP_Filter : String;
  LuP_ISwitch : Integer;

begin
  // MiK doplnění atributů do 102,0 (spouštět jako BI)
  SL := TStringList.Create;
  try
    if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '102,0', '40241202,10') then begin
    
      // 102,0
      SL.Clear;
      SL.Values['ic'] := '40241202';        
      SL.Values['u'] := '10';                    
      SL.Values['221,1'] := 'Externí název (Qi2)';  
      SL.Values['222,0'] := '1';  
      SL.Values['244,0'] := '0';    
      SL.Values['2204,0'] := '3';    
      SL.Values['2205,0'] := '1';      
      SL.Values['2257,0'] := '3';          
      SL.Values['2240,0'] := '0';            
      SL.Values['223,0'] := '50';  
      SL.Values['225,1'] := '1';                  
      SL.Values['224,1'] := '0';      
      AppServer.InsertDBRecord(SourceName, UserLang, '102,0', False, SL);  
    
      // 103,0
      SL.Clear;
      SL.Values['ic'] := '40241203';        
      SL.Values['u'] := '10';              
      SL.Values['ic_a'] := '102';        
      SL.Values['u_a'] := '0';        
      SL.Values['ic_b'] := '40241202';        
      SL.Values['u_b'] := '10';                    
      AppServer.InsertDBRecord(SourceName, UserLang, '103,0', False, SL);            
    end;
  finally
    SL.Free;
  end;      
  // MiK konec
  
  
  AppServer.SetSQLScript(SourceName,TargetPath + 'Reinstall_1101BI.sql');
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  M17059359_10;  // NEMAZAT, STANDARDNI SOUCAST REINSTALACE  
  AppServer.SetSQLScript(SourceName,TargetPath + 'Reinstall_1101AD.sql');
  
  // MaSu Přesypání "Role, profese - zodpovídá" do "Požadavky procesu na role a profese" (NESPOUSTET)
  DS := TAppDataSet.Create;
  SL := TStringList.Create;
  try
    DS.SetDSParams(SourceName,rmPrimary,'40253201,10',dsaReadNonVisible);
    DS.Open;
    while not DS.EOF do
    begin
      if not AppServer.ExistDBKeyValue(SourceName,rmPrimary,'5925961,10',DS.GetPKValue) then
      begin
        SL.Clear;
        SL.Values['ic'] := LByID(DS.GetPKValue);
        SL.Values['u'] := RByID(DS.GetPKValue);
        SL.Values['ic_a'] := LByID(DS.GetKeyValue('',ftIDA)); 
        SL.Values['u_a'] := RByID(DS.GetKeyValue('',ftIDA));
        SL.Values['ic_b'] := LByID(DS.GetKeyValue('',ftIDB)); 
        SL.Values['u_b'] := RByID(DS.GetKeyValue('',ftIDB));
        AppServer.InsertDBRecord(SourceName,'','5925961,10',true,SL);
      end;
      DS.Next;
    end;
  finally
    DS.Free;
    SL.Free;
  end;
  // MaSu konec
  
  //LuP: udrzba obsazenosti manipulacnich jednotek ve stavech zasob (NESPOUSTET)
  //prepocet na zaklade manipulacnich jednotek
  LuP_ContenctMNUDS := TAppDataSet.Create;
  try
    LuP_ContenctMNUDS.SetDSParams(SourceName, rmPrimary, '39911992,10', dsaReadNonVisible);
    LuP_Filter := '("39911997,10.ic" is not null and "39911997,10.u" is not null) and ' //ma sklad
                + '("39922240,10" is not null and "39922240,10" in (1,2)) and '  //je v prislusnem stavu (Zabalena, Rozbalena)
                + '("40061797,10" is null or "40061797,10" = 0) and '            //platna polozka
                + '("39912048,10" is not null and "39912048,10" > 0) and '       //ma platne mnozstvi
                + '(("40235900,10.ic" is null and "40235900,10.u" is null) or '  //neni v nadrizene
                +  '("40236249,10.ic" is null and "40236249,10.u" is null))';    //nebo nadrizena nema sklad
    LuP_Filter := '(' + LuP_Filter + ')';
    LuP_ContenctMNUDS.Filter := LuP_Filter;  
    LuP_ContenctMNUDS.Open;
    if not LuP_ContenctMNUDS.IsEmpty then begin
      while not LuP_ContenctMNUDS.EOF do begin
        LuP_Switch := LuP_ContenctMNUDS.FieldByName('39923049,10').AsString;
        if LuP_Switch = '1' then
          LuP_Switch := '0'
        else
          LuP_Switch := '1';
        AppServer.SetDBAtrValue(SourceName, '', '30610999,10', '39911813,10', LuP_ContenctMNUDS.GetKeyValue('', ftID), LuP_Switch);
        //
        LuP_ContenctMNUDS.Next;
      end;
    end;
  finally
    LuP_ContenctMNUDS.Free;
  end;
end.
  
